package de.jmda.sample.mproc.task;

import static de.jmda.core.mproc.ProcessingUtilities.getElementsAnnotatedWith;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Set;

import javax.lang.model.element.Element;

import org.junit.Test;

import de.jmda.core.mproc.task.AbstractAnnotatedElementsTask;
import de.jmda.core.mproc.task.TaskException;
import de.jmda.core.mproc.task.TaskRunner;
import de.jmda.core.util.TypeUtil;
import de.jmda.core.util.FileUtil;
import de.jmda.core.util.fileset.FileSet;

public class JUTHelloWorldAnnotatedElementsTask
{
	private class SampleTask extends AbstractAnnotatedElementsTask
	{
		public SampleTask(
				Set<Class<? extends Annotation>> annotationTypes, FileSet fileset)
    {
	    super(annotationTypes, fileset);
    }

		@Override
		public boolean execute() throws TaskException
		{
			System.out.println("Hello World!");

			for (Class<? extends Annotation> annotationType : getAnnotationTypes())
			{
				for (Element element : getElementsAnnotatedWith(annotationType))
				{
					System.out.println("Welcome " + element.getSimpleName() + ".");
				}
			}

			return false;
		}
	}

	@Test
	public void test() throws IOException
	{
		SampleTask task =
				new SampleTask(
						TypeUtil.createAnnotationsSet(Test.class),
						FileUtil.createFileSet(getClass(), "src/test/java"));

		TaskRunner.run(task);
	}
}